Get Operating System Version 
  
 Print  
  Email  
  
 
 
 
 Submitted on: 5/21/2001 7:42:31 AM
By: venky_dude 

Level: Beginner
User Rating:      By 3 Users
Compatibility:VB 6.0

Users have accessed this article 714 times.
   
(About the author) 
 
  
     A few Lines of code to show you the version of windows you are running.

--------------------------------------------------------------------------------
 
 
  
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.  
The Api used for this are

 

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long


Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type

The GetVersion Api just takes one parameter of type OSVERSIONINFO. The OSVERSIONINFO structure will contain all the details about the OS after GetVersionApi has been successfully executed. The parameters of  OSVERSIONINFO are 

dwMajorVersion which gives info about the major version of the OS .This value is  3 for win Nt 3.51, 4 for win95/98/me and win nt4 and it is 5 for win2k. 
dwMinorVersion ,another parameter to differentiate the OS further .It is 0 for win 95,10 for win 98 ,98 for win ME,0   for win2k ,0 for win nt4 and 51 for win nt 3.51 
dwPlatformId  .This is an important parameter which helps in further differentiating the varios win OS.It is 1 for win 95/ 98/ME ,and 2 for win NT   
Once Declared we can use this in the following way

Dim os As OSVERSIONINFO 


os.dwOSVersionInfoSize = Len(os)     'Assign some size to store the received information

Dim m As Long
Dim mv As Long
Dim pd As Long
Dim miv As Long
m = GetVersionEx(os)        'The actual API call to GetVersionEx
mv = os.dwMajorVersion
pd = os.dwPlatformId
miv = os.dwMinorVersion
If pd = 2 Then MsgBox " OS is Windows NT" & mv & "." & miv
If pd = 1 Then
If miv = 10 Then MsgBox " OS is Windows 98 "
If miv = 0 Then MsgBox " OS is Windows 95 "
If miv = 90 Then MsgBox " OS is Windows ME "
End If



This can be quite useful if you are making OS specific Applications. Send your comments to venky_dude@yahoo.com. .Visit my homepage for some cool VBcodes.   

 

 

 

Other 25 submission(s) by this author
 
 
 
  
Report Bad Submission 
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:  
  
Your Vote! 

What do you think of this article(in the Beginner category)?
(The articlewith your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor     
See Voting Log  
  
Other User Comments 
7/18/2001 9:22:16 AM:erebus
gg
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
 
7/18/2001 9:23:23 AM:erebus
ive been looking for a simple code that can pick up which 9x,me,and nt. thanky.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
 
7/30/2001 12:52:44 AM:Kourosh Gonabadi
Very Cool, Thanks man it worked great.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
 
9/27/2001 12:21:48 AM:Alex M-G
thank you very much for posting this useful code. i have seen the api before but did not know what the return values from the parameters of OSVERSIONINFO where. i added 1 line of code to display "Windows 2000" instead of "Windows NT5". here is and example: If pd = 2 And mv = 5 Then MsgBox "OS is Windows 2000" i did this because a lot of people do not realise that WindowsNT5 is actually referring to Windows2000. thanks again.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:
 
